@page
@model ModelBindingSample.Pages.InstructorsWithDictionary.CreateModel

@{
    ViewData["Title"] = "Create Instructor with Courses Dictionary";
}

<h2>Create</h2>

<h4>Instructor with Courses Dictionary</h4>
<hr />
<div class="row">
    <div class="col-md-4">
        <form method="post">
            <div asp-validation-summary="All" class="text-danger"></div>
            <div class="form-group">
                <label asp-for="Instructor.LastName" class="control-label"></label>
                <input asp-for="Instructor.LastName" class="form-control" />
                <span asp-validation-for="Instructor.LastName" class="text-danger"></span>
            </div>
            <div class="form-group">
                <label asp-for="Instructor.FirstMidName" class="control-label"></label>
                <input asp-for="Instructor.FirstMidName" class="form-control" />
                <span asp-validation-for="Instructor.FirstMidName" class="text-danger"></span>
            </div>
            <div class="form-group">
                <label asp-for="Instructor.HireDate" class="control-label"></label>
                <input asp-for="Instructor.HireDate" class="form-control" />
                <span asp-validation-for="Instructor.HireDate" class="text-danger"></span>
            </div>
            <div class="form-group">
                <label asp-for="Instructor.Courses" class="control-label"></label>
                <div class="col-md-offset-2 col-md-10">
                    <table>
                        @{
                            int cnt = 0;

                            foreach (var course in Model.Instructor.Courses)
                            {
                                <tr>
                                    @{
                                        int format = 1;
                                        if (format == 1)
                                        {
                                            <!-- parameter_name[key]=value-->
                                            <!-- instructor.Courses[1050]=Chemistry&instructor.Courses[4022]=Microeconomics&instructor.Courses[4041]=Macroeconomics -->
                                            <td>
                                                @course.Key
                                            </td>
                                            <td>
                                                <input asp-for="Instructor.Courses[course.Key]" value="@course.Value" />
                                            </td>
                                        }
                                        else if (format == 2)
                                        {
                                            <!-- parameter_name[0].Key=key&parameter_name[0].Value=value -->
                                            <!-- instructor.Courses[0].Key=1050&instructor.Courses[0].Value=Chemistry&instructor.Courses[1].Key=4022&instructor.Courses[1].Value=Microeconomics&instructor.Courses[2].Key=4041&instructor.Courses[2].Value=Macroeconomics -->
                                            <td>
                                                <input name="instructor.Courses[@cnt].Key" type="text" value="@course.Key" />
                                            </td>
                                            <td>
                                                <input name="instructor.Courses[@cnt].Value" type="text" value="@course.Value" />
                                            </td>
                                        }

                                        cnt++;
                                    }
                                </tr>
                            }
                        }
                    </table>
                </div>
            </div>
            <div class="form-group">
                <input type="submit" value="Create" class="btn btn-primary" />
            </div>
        </form>
    </div>
</div>

<div>
    <a asp-page="Index">Back to List</a>
</div>

@*@section Scripts {
        @{await Html.RenderPartialAsync("_ValidationScriptsPartial");}
    }*@
